import { createRouter, createWebHistory } from 'vue-router'
import routes from './routes'
import { useAuthStore } from '@/stores/auth'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: routes
})

router.beforeEach((to, from) => {
  if (to?.meta?.requiredAuth) {
    let AuthStore = useAuthStore
    if(AuthStore.isLogin){
      return true
    }else{
      let route = router.currentRoute.value //router.currentRoute 返回的当前路由信息是ref对象
      router.push({path:"/login",query:{ReturnUrl:router.fullPath}})
    }
  } else {
    return true // 没有验证直接返回true
  }
})

export default router
